import request from "./useRequests";
import { userinfo } from '@/stores/counter'
import { ElMessage } from 'element-plus'

export default function getUser() {
    const user = userinfo()
    async function getComments() {
        if (!user.baseInfo.id) return
        try {
            const res = await request({
                method: "get",
                url: `/user/getUser`,
                params: {
                    "id": user.baseInfo.id
                }
            })
            // console.log(res.data)
            // user.comments = res.data.data.Comments
            return res.data.data.Comments

        } catch (err: any) {
            // //alert(err)
        }
    }

    async function getName(id: number) {
        try {
            if (user.knowNickName[id]) {
                return user.knowNickName[id]
            }
            const res = await request({
                method: "get",
                url: `/user/getUser`,
                params: {
                    "id": id
                }
            })
            user.knowNickName[id] = res.data.data.nickName
            return res.data.data.nickName

        } catch (err: any) {
            //alert(err)
        }
    }

    return {
        getComments, getName
    }
}